

import { useModel } from '@umijs/max';
import { Button, message, Popconfirm, Tree } from 'antd';
import React, { useEffect, useState } from 'react';

const FuncList: React.FC = () => {
    const {arr2tree,getHandler,removeHandler}=useModel("Function.model",(model)=>{
        return{
              arr2tree:model.arr2tree,
              getHandler:model.getHandler,
              removeHandler:model.removeHandler
        }
    })
    
    const [funcDate,setFuncDate]=useState([]);
    useEffect(()=>{
        (async()=>{
             const data:any=await getHandler();
             setFuncDate(data);
        })()
    },[setFuncDate])
    
   const treeData=arr2tree(funcDate);
    const fieldNames={
        title:'func_name',
        key:'func_id',
        children:'children'
    }
     
    return (
        <>
        <Tree
            treeData={treeData}
            fieldNames={fieldNames}
            titleRender={(node)=>{
                return (
                  <>
                    <span>{node.func_name}</span>
                    {node.func_id !== 2 && node.func_fid !== 1 && (
                      <Button style={{ marginLeft: '100px' }}>新建</Button>
                    )}
                    {node.func_id !== 2 && (
                      <Button style={{ marginLeft: '100px' }}>修改</Button>
                    )}
                    {node.func_fid !== 0 && node.func_id !== 2 && (
                        <Button
                        //   style={{ marginLeft: '100px', color: 'red' }}
                        onClick={() => {removeHandler(node.func_id)}}
                        >
                          删除
                        </Button>
                    //   <Popconfirm
                    //     title={'你确定要删除吗？'}
                    //     onCancel={() => message.info('你取消了操作')}
                    //     placement="topRight"
                    //   >
                    //     <Button
                    //       danger
                    //       onClick={() => removeHandler(node.func_id)}
                    //     >
                    //       删除{' '}
                    //     </Button>
                    //   </Popconfirm>
                    )}
                  </>
                ); 
                    
            }}
        />
        </>
    );


 


};

export default FuncList;

